public class Demo3 {
    public static void main(String[] args) {
        int sum = 0;
        for (int i = 1; i <= 2020; i++) {
            String str = i + "";
            char[] ch = str.toCharArray();
            for (int j = 0; j < ch.length; j++) {
                if (ch[j] == '2') {
                    sum++;
                }
            }
        }
        System.out.println(sum);
    }
}
